home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bchelp10.zip / TI728.ASC < prev    next >
Text File  |  1991-09-18  |  11KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Borland C++                            NUMBER  :  728
  8.   VERSION  :  2.0
  9.        OS  :  DOS
  10.      DATE  :  September 18, 1991                       PAGE  :  1/6
  11.  
  12.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  13.               C++
  14.  
  15.  
  16.  
  17.  
  18.   COMPILING IN C++
  19.   ----------------
  20.   When using Borland C++, problems with the examples from Charles
  21.   Petzold's Programming Windows will often result from compiling
  22.   them unmodified in C++ mode.  Here are some symptoms of this
  23.   problem which you may run across when compiling the examples from
  24.   Programming Windows:
  25.  
  26.      1.  HELLOWIN example does not display the text until it is
  27.          painted a second time
  28.  
  29.      2.  KEYLOOK example hangs with hourglass
  30.  
  31.      3.  CLOVER example does not print anything
  32.  
  33.      4.  GetSystemMetrics (or other API functions) give unusual
  34.          results
  35.  
  36.   The quick and obvious solution to this problem is to switch the
  37.   compiler back to C mode.  However, it IS quite possible to
  38.   compile these programs in C++ by making some minor modifications.
  39.  
  40.   The Petzold DEF files do not contain the C++ name mangled names
  41.   for the exported functions.  If the programs are to be compiled
  42.   as C++, the _export modifier should be used for any functions to
  43.   be exported.  The function entries in the EXPORTS section of the
  44.   DEF file can then be removed.  Following this method, the
  45.   declaration for a sample exported function would be:
  46.  
  47.   long  FAR PASCAL _export WndProc (HWND, WORD, WORD, LONG) ;
  48.  
  49.   An alternative way to export the functions would be to leave the
  50.   EXPORTS entry in the DEF file as is and declare the function as
  51.   extern "C" in the C++ source code.  This will "turn off" name
  52.   mangling for that function and thus the identifier for that
  53.   function will match the one exported in the DEF file.  Following
  54.   this method, the declaration for a sample exported function would
  55.   be:
  56.  
  57.   extern "C" long  FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  58.  
  59.   COMPILING IN C
  60.   --------------
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.   PRODUCT  :  Borland C++                            NUMBER  :  728
  74.   VERSION  :  2.0
  75.        OS  :  DOS
  76.      DATE  :  September 18, 1991                       PAGE  :  2/6
  77.  
  78.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  79.               C++
  80.  
  81.  
  82.  
  83.  
  84.   The same symptoms described in the section above can occur when
  85.   compiling in C mode if you have not included the program's .DEF
  86.   file when linking your program.  If you are using BC or BCX, this
  87.   means you need to have a project file that includes your .DEF
  88.   file in addition to your .C file (and .RC file if one exists).
  89.   If you are using BCC or BCCX and calling TLINK directly, this
  90.   means that you have forgotten to include the .DEF file on your
  91.   TLINK command line.  See the Borland C++ User's Guide for more
  92.   information on TLINK.
  93.  
  94.   SYSMETS EXAMPLE
  95.   ---------------
  96.   In the SYSMETS2 example (page 73), max and min can return
  97.   incorrect values because NUMLINE returns an unsigned int rather
  98.   than an int.
  99.  
  100.   The problem has to do with the NUMLINES macro defined at the top
  101.   of SYSMETS.H (page 59).  As required by ANSI, sizeof returns an
  102.   unsigned.  This, combined with the max and min macros, results in
  103.   nVscrollPos never appearing to be less than 0.  Changing the
  104.   NUMLINES macro to:
  105.  
  106.   #define NUMLINES  ((int)sizeof sysmetrics/(int) sizeof sysmetrics[0])
  107.  
  108.   will resolve this problem.
  109.  
  110.   In addition, it should be noted that the max and min macros are
  111.   not defined in the C++ language.  The reason for this omission is
  112.   to allow C++ programmers to overload the function names min and
  113.   max.  To compile this example as C++, the min and max macros
  114.   should be copied from windows.h directly into the SYSMETS2.C
  115.   source file.
  116.  
  117.   DDEPOP / SHOWPOP EXAMPLE
  118.   ------------------------
  119.   Line 573 of DDEPOP.C declares a character array in the function
  120.   PostDataMessage as follows:
  121.  
  122.   char    szPopulation [10];
  123.  
  124.   This line should read:
  125.  
  126.   char    szPopulation [11];
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   PRODUCT  :  Borland C++                            NUMBER  :  728
  140.   VERSION  :  2.0
  141.        OS  :  DOS
  142.      DATE  :  September 18, 1991                       PAGE  :  3/6
  143.  
  144.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  145.               C++
  146.  
  147.  
  148.  
  149.  
  150.   Without this modification, a UAE will occur when running its
  151.   client program SHOWPOP.EXE.
  152.  
  153.   Note that there is a similar declaration on line 239 in the
  154.   function ServerProc.  Do not confuse this declaration with the
  155.   one on line 573.  Since the array szPopulation is never used in
  156.   the function ServerProc, you may remove the declaration of
  157.   szPopulation from line 239.
  158.  
  159.   BTNLOOK EXAMPLE
  160.   ---------------
  161.   On line 24 of BTNLOOK.C, change BS_USERBUTTON to BS_OWNERDRAW.
  162.   BS_USERBUTTON is not a style documented by Microsoft for
  163.   Microsoft Windows 3.0.
  164.  
  165.   READ VERSUS _LREAD
  166.   ------------------
  167.   Microsoft Windows defines a set of functions for file management
  168.   which are separate from the file management functions used in
  169.   traditional DOS applications.  Microsoft C 6.0 happens to allow
  170.   the free mixture of Windows file handles created with OpenFile()
  171.   and standard DOS file handles created with open().  This
  172.   "feature" is undocumented and therefore not standard Windows
  173.   programming.  In Borland C++, Windows file handles and DOS file
  174.   handles are not the same and cannot be freely mixed in calls to
  175.   functions.
  176.  
  177.   Some of the Programming Windows examples make calls to OpenFile()
  178.   and use the resulting handle in a call to read().  To make such
  179.   examples work when compiling with Borland C++, it will be
  180.   necessary to commit your program to one system of file management
  181.   or the other.  If you choose to use OpenFile(), calls to read()
  182.   and write() should be converted to calls to _lread() and
  183.   _lwrite().   If you choose to continue with calls to read()
  184.   and write(), the call to OpenFile should be converted to a call
  185.   to open().
  186.  
  187.   MAKE FILES
  188.   ----------
  189.   The make files provided for the examples in Programming Windows
  190.   were designed with Microsoft C in mind and are not compatible
  191.   with Borland C++.  Here is an example Borland makefile which can
  192.   be used for the simpler single file Windows programs.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.   PRODUCT  :  Borland C++                            NUMBER  :  728
  206.   VERSION  :  2.0
  207.        OS  :  DOS
  208.      DATE  :  September 18, 1991                       PAGE  :  4/6
  209.  
  210.     TITLE  :  Issues with Petzold's Programming Windows and Borland
  211.               C++
  212.  
  213.  
  214.  
  215.  
  216.   --- cut here ---
  217.   #
  218.   # Borland C++ makefile for Charles Petzold's Programming Windows
  219.   # examples
  220.   #
  221.   #      Instructions:  1) Change "file" to the name of the example
  222.   #                        program being compiled.
  223.   #                     2) If the example you are compiling does
  224.   #                        not have an RC file, remove all
  225.   #                        references to "file.res".
  226.   #                     3) Modifications will be necessary for
  227.   #                        multifile examples.  Consult the
  228.   #                        Borland C++ User's Guide.
  229.   #
  230.   file.exe : file.obj file.def file.res
  231.           bccx -W file.obj
  232.           rc file.res file.exe
  233.           # if the example does not contain an RC file, remove
  234.           # "file.res" from the line above
  235.  
  236.   file.obj : file.c
  237.           bccx -W -c file.c
  238.  
  239.   # if the example does not contain an RC file, remove the rule
  240.   # below
  241.   file.res :
  242.           rc -r file.rc
  243.  
  244.   --- cut here ---
  245.  
  246.   Note that a DEF file called file.def would be linked in
  247.   automatically.  If file.def does not exist, default values would
  248.   be used.
  249.  
  250.   More complex, multifile examples are most easily built using the
  251.   project manager of BCX or BC.  Select "Open Project" from the
  252.   "Project" menu.  Give your project a name (this will also be the
  253.   name of your executable).  A project window will appear.  Select
  254.   the project window and hit the "insert" key.  You will be
  255.   prompted for the names of the s